import { Body, Controller, Post } from "@nestjs/common";
import { PatientService } from "./patient.service";
import { Patient as PatientModel } from "@prisma/client";
import { NoNeedLogin } from "../../../../libs/decorator/no-need-login/no-need-login.decorator";

@Controller("patient")
export class PatientController {
  constructor(private readonly patientService: PatientService) {}

  @Post("query-patients")
  @NoNeedLogin()
  handleQueryPatients() {
    return this.patientService.getPatients();
  }

  @Post("add-patient")
  async handleAddPatients(@Body() params: PatientModel) {
    console.log("收到请求", params);
    const { patientIndex, ...newObject } = Object.assign({}, params);
    return await this.patientService.createPatient(newObject);
  }

  @Post("delete-patient")
  async handleDeletePatient(@Body() params: any): Promise<any> {
    return await this.patientService.deletePatient(params.patientIDList);
  }

  @Post("update-patient")
  async handleUpdatePatient(@Body() params: any): Promise<any> {
    return await this.patientService.updatePatient(params);
  }
}
